Skip to content

[scramjet/controller] polish controller api for consumers#44

Open
Percslol wants to merge 7 commits intoHeyPuter:developfrom
Percslol:develop
Open

[scramjet/controller] polish controller api for consumers#44
Percslol wants to merge 7 commits intoHeyPuter:developfrom
Percslol:develop

Conversation

@Percslol
Copy link
Copy Markdown
Contributor

No description provided.

@Percslol Percslol marked this pull request as draft April 19, 2026 04:00
Comment thread packages/scramjet/packages/controller/src/index.ts Outdated
@velzie
Copy link
Copy Markdown
Collaborator

velzie commented Apr 23, 2026

and do we want controller.transport = ... controller.scramjetconfig = ... or controller.setTransport / controller.setConfig

@Percslol Percslol marked this pull request as ready for review April 23, 2026 04:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to polish the @mercuryworkshop/scramjet-controller consumer-facing API and align the demo with the updated controller surface, while also removing the rewriter_demo package and updating lockfiles accordingly.

Changes:

  • Update controller API to expose config/scramjetConfig and move consumer usage toward controller.wait() and controller.scramjetConfig.flags.
  • Remove the packages/scramjet/packages/rewriter_demo demo package and its dependencies from lockfiles.
  • Refresh pnpm lockfiles (tooling/version shifts, dependency graph changes).

Reviewed changes

Copilot reviewed 9 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pnpm-lock.yaml Updates workspace dependency resolutions; removes rewriter_demo importer and adjusts tooling deps.
packages/scramjet/pnpm-lock.yaml Removes set-cookie-parser entry from scramjet workspace lockfile.
packages/scramjet/packages/rewriter_demo/src/style.css Deleted as part of removing rewriter_demo.
packages/scramjet/packages/rewriter_demo/src/main.js Deleted as part of removing rewriter_demo.
packages/scramjet/packages/rewriter_demo/public/vite.svg Deleted as part of removing rewriter_demo.
packages/scramjet/packages/rewriter_demo/package.json Deleted as part of removing rewriter_demo.
packages/scramjet/packages/rewriter_demo/index.html Deleted as part of removing rewriter_demo.
packages/scramjet/packages/rewriter_demo/.gitignore Deleted as part of removing rewriter_demo.
packages/scramjet/packages/demo/src/index.tsx Updates demo initialization to new controller API and exports controller.
packages/scramjet/packages/demo/src/App.tsx Updates flags editing to write into controller.scramjetConfig.flags.
packages/scramjet/packages/controller/src/types.d.ts Adjusts exported types but currently breaks by removing an import that is still referenced.
packages/scramjet/packages/controller/src/inject.ts Aligns injected runtime types and client init behavior with new controller config structure.
packages/scramjet/packages/controller/src/index.ts Introduces config/scramjetConfig on Controller and adds merge support, plus inject script changes.
Files not reviewed (2)
  • packages/scramjet/pnpm-lock.yaml: Language not supported
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

packages/scramjet/packages/demo/src/index.tsx:57

  • controller is declared without an initializer and with a non-optional type, but it’s read in swapTransport before init() necessarily assigns it. Under strictPropertyInitialization/definite assignment analysis this pattern commonly triggers “Variable 'controller' is used before being assigned”, and at runtime it can still be undefined if swapTransport is called early. Declare it as Controller | undefined (or use a definite assignment assertion let controller!: … if you guarantee assignment before use) and keep the guard consistent.
let controller: ScramjetControllerGlobal.Controller;

export async function swapTransport(wispUrl: string) {
	const nextTransport = new LibcurlClient({
		wisp: wispUrl,
	});

	transport = nextTransport;

	if (!controller) {
		return;
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 411 to +416
constructor(public init: ControllerInit) {
this.transport = init.transport;
this.id = makeId();
this.prefix = config.prefix + this.id + "/";
this.config = deepMerge(config, init.config);
this.scramjetConfig = deepMerge($scramjet.defaultConfig, scramjetConfig);
this.scramjetConfig = deepMerge(this.scramjetConfig, init.scramjetConfig);
this.prefix = this.config.prefix + this.id + "/";
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new config?: Partial<Config> option is merged into this.config, but several code paths still use the module-level config constant (e.g. loadScramjetWasm() and the virtual wasm request handling). This means per-controller overrides like init.config.wasmPath / virtualWasmPath won’t actually take effect. Use this.config (or pass the resolved config into helpers) consistently anywhere the controller reads paths/codec config.

Copilot uses AI. Check for mistakes.
Comment on lines +170 to +178
function deepMerge(target: any, source: any): any {
for (const key in source) {
if (key in target) {
Object.assign(source[key], deepMerge(target[key], source[key]));
}
}

type ControllerInit = {
serviceworker: ServiceWorker;
transport: ProxyTransport;
};
return Object.assign(target || {}, source);
}
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deepMerge is not safe for the way it’s used in the constructor: init.config / init.scramjetConfig are optional and can be undefined, but for (const key in source) will throw on undefined/null. It also does Object.assign(source[key], ...) without checking that source[key] is an object, which can throw for primitives, and it mutates both source and target (so calling deepMerge(config, …) can inadvertently mutate the exported config constant and $scramjet.defaultConfig). Consider replacing this with a non-mutating deep merge that treats non-plain objects/arrays as leaf values and gracefully handles undefined sources.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants